import React, { FC, useRef } from 'react';
import Login from '../../../components/login';
import { httpJson } from "../../../services/http";
import { useHistory } from 'react-router-dom';
import { set } from '../../../utils/storage';

// 商家登录页
const MerLogin: FC = props => {
    const history = useHistory();
    const merRef = useRef<any>();

    const login = () => {
        console.log("可以拿到商家登录信息", merRef.current.getFieldsValue());
        httpJson('POST', '/api/merchant/login', merRef.current.getFieldsValue())
            .then((res: any) => {
                console.log("商家登录成功返回信息", res);
                if (res.data.code == '200') {
                    set("sessionId", res.data.data.sessionId);
                    set("merchantId", res.data.data.user.id);
                    history.push("/merchant");
                }
            })
            .catch(err => {
                console.log(err)
            })
    }
    
    return <Login login={login} valueLink="我要开店" agreement="《云食团餐商家隐私政策》" ref={merRef} />
}
export default MerLogin;
